package mall.core;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author xf07b1
 * @wechat xf07b1
 * @description
 */
public class ApplicationProperties {
    public static final String VIEW_PREFIX;
    public static final String VIEW_SUFFIX;

    public static final String JDBC_DRIVER;
    public static final String JDBC_URL;
    public static final String JDBC_USERNAME;
    public static final String JDBC_PASSWORD;

    static {
        Properties properties = new Properties();
        try (InputStream inputStream = ApplicationProperties.class.getClassLoader().getResourceAsStream("application.properties")) {
            if (inputStream == null) {
                throw new RuntimeException("File application.properties not found");
            }
            properties.load(inputStream);

            VIEW_PREFIX = properties.getProperty("view.prefix", "/WEF-INF/views");
            VIEW_SUFFIX = properties.getProperty("view.suffix", ".jsp");

            JDBC_DRIVER = properties.getProperty("jdbc.driver");
            JDBC_URL = properties.getProperty("jdbc.url");
            JDBC_USERNAME = properties.getProperty("jdbc.username");
            JDBC_PASSWORD = properties.getProperty("jdbc.password");

        } catch (IOException e) {
            throw new RuntimeException("Load application.properties failed", e);
        }
    }
}
